<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>两数之和</title>
</head>
<body>
  <!-- 写一个数，判断数组中的哪些数字相加等于它 -->
  <script>
    let num = [2, 7, 11, 15, 20, 24]
    function fn(target) {
      var obj = {}
      for(let i = 0; i < num.length; i++) {
        obj.a = i
        for(let j = 0; j < num.length; j++){
            obj.b = j
            // console.log(i, j);
            // 判断 num[i] 里面的哪个元素 + num[j] 里面的哪个元素 = target
            if(num[i] + num[j] == target){
              // values 将属性值合并为一个新数组
              return Object.values(obj)
            }
        }
      }
    }
    console.log(fn(22))
  </script>
</body>
</html>